// pages/S-details/S-details.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    list: '',
    imgApi: app.globalData.imgApi,
    madeTemplateTime: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(e) {
    this.setData({
      id: e.id
    })
    var that = this
    wx.request({
      url: app.globalData.api + 'designDiagram/' + e.id,
      data: {},
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function(res) {
        console.log(res)
        that.setData({
          list: res.data.data,
          img: res.data.data.designImage.split(','),
          Ddate: res.data.data.madeTemplateTime.split(' ')[0],
          brand: res.data.data.brand.split(','),
          size: res.data.data.size.split(','),
          colour: res.data.data.color.split(',')
        })
      }
    })
  },
  adopt: function() {
    wx.request({
      url: app.globalData.api + 'designDiagram/confirm/' + this.data.id,
      data: {
        confirm: true
      },
      method: 'PUT',
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function(res) {
        console.log(res)
        if (res.data.code == 200) {
          wx.showToast({
            title: res.data.msg,
          })
          setTimeout(() => {
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
        }
      }
    })
  },
  noAdopt: function() {
    wx.request({
      url: app.globalData.api + 'designDiagram/confirm/' + this.data.id,
      data: {
        confirm: false
      },
      method: 'PUT',
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function(res) {
        console.log(res)
        if (res.data.code == 200) {
          wx.showToast({
            title: res.data.msg,
          })
          setTimeout(() => {
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
        }
      }
    })
  },
  Delete: function() {
    var that = this
    wx.showModal({
      title: '提示',
      content: '确定删除?',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.api + 'designDiagram/' + that.data.id,
            data: {},
            method: 'DELETE',
            header: {
              Authorization: wx.getStorageSync('token')
            },
            success: function(res) {
              console.log(res)
              if (res.data.code == 200) {
                wx.showToast({
                  title: res.data.msg,
                })
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1000)
              } else {
                wx.showToast({
                  icon: 'none',
                  title: res.data.errorMsg,
                })
              }
            }
          })
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})